#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define in read()
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mes(x) memset(x,0,sizeof(x))
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int MAXN = 5e5+10;
const int inf = 0x3f3f3f3f;

int f[MAXN],cnt,val[MAXN<<2],lz[MAXN<<2],d[MAXN],top[MAXN],son[MAXN],siz[MAXN],dep[MAXN],fa[MAXN],n,m,k,tot,dfn[MAXN],v[MAXN];
struct edge{int tp,u,v,w;}e[MAXN<<1];
struct node{int tp,v,w;};
vector<node>T[MAXN];
vector<edge>unma;
ll ans = 0;
int gf(int x){return f[x] == x ? x : f[x] = gf(f[x]);}

void pushdown(int o){
	if(lz[o] < inf){
		lz[o<<1] = min(lz[o<<1],lz[o]); lz[o<<1|1] = min(lz[o<<1|1],lz[o]);
		val[o<<1] = min(val[o<<1],lz[o]); val[o<<1|1] = min(val[o<<1|1],lz[o]);
		lz[o] = inf;
	}
}

void update(int xl,int xr,int v,int o = 1,int l = 1,int r = n){
	if(xl == l && xr == r){if(v < val[o]) val[o] = v,lz[o] = min(lz[o],v);return;}
	int mid = l+r>>1;
	pushdown(o);
	if(xr <= mid) update(xl,xr,v,o<<1,l,mid);
	else if(xl > mid) update(xl,xr,v,o<<1|1,mid+1,r);
	else update(xl,mid,v,o<<1,l,mid),update(mid+1,xr,v,o<<1|1,mid+1,r);
	val[o] = min(val[o<<1],val[o<<1|1]);
}

void calc(int o = 1,int l = 1,int r = n){
	if(val[o] == inf){puts("-1");exit(0);}
	if(l == r) return (void)(v[l] = val[o]);
	pushdown(o);
	int mid = l+r>>1;
	calc(o<<1,l,mid); calc(o<<1|1,mid+1,r);
}

void dfs(int x,int p){
	fa[x] = p;dep[x] = dep[p]+1; siz[x] = 1;son[x] = 0;
	for(auto d : T[x]){
		int y = d.v; if(y == p) continue; v[y] = d.tp ? 0 : inf;
		dfs(y,x); siz[x] += siz[y]; if(siz[y] > siz[son[x]]) son[x] = y;
	}
}

void dfs(int x){
	top[x] = son[fa[x]] == x ? top[fa[x]] : x; dfn[x] = ++tot; d[dfn[x]] = v[x];
	if(son[x]) dfs(son[x]); for(auto d : T[x]) if(d.v != fa[x] && d.v != son[x]) dfs(d.v);
}

void modify(int x,int y,int w){
	while(top[x] != top[y]){
		if(dep[top[x]] < dep[top[y]]) swap(x,y);
		update(dfn[top[x]],dfn[x],w);
		x = fa[top[x]];
	}
	if(dfn[x] != dfn[y]) {if(dfn[x] > dfn[y]) swap(x,y); update(dfn[x]+1,dfn[y],w);}
}

void build(int o = 1,int l = 1,int r = n){
	lz[o] = inf; val[o] = inf;
	if(l == r) return (void)(val[o] = d[l]);
	int mid = l + r>>1;
	build(o<<1,l,mid);build(o<<1|1,mid+1,r);
	val[o] = min(val[o<<1] , val[o<<1|1]);
}

int main (){
	n = in,m = in,k = in;
	for(int i = 1;i <= m;i++) e[++cnt] = (edge){0,in,in,0};
	for(int i = 1;i <= k;i++) e[++cnt] = (edge){1,in,in,in};
	for(int i = 1;i <= n;i++) f[i] = i;
	for(int i = 1;i <= cnt;i++){
		int x = e[i].u,y = e[i].v; x = gf(x) , y = gf(y);
		if(x != y){
			f[x] = y; T[e[i].u].pb((node){e[i].tp,e[i].v,e[i].w}); T[e[i].v].pb((node){e[i].tp,e[i].u,e[i].w});
		}else {unma.pb((edge){0,e[i].u,e[i].v,e[i].w});}
	}memset(val,0x3f,sizeof(val)); memset(lz,0x3f,sizeof(lz));
	dfs(1,0); dfs(1); build();
	for(auto d : unma){
		int x = d.u,y = d.v,w = d.w;
		modify(x,y,w);
	}
	calc(); for(int i = 1;i <= n;i++) ans += v[i];
	printf("%lld\n",ans);
	return 0;
}

